package com.lun.easy;

public class FibonacciNumber {
	
	//方法一
    public int fib(int n) {
    	int first = 0, second = 1;
    	
    	for(int i = 1; i <= n; i++) {
    		int newOne = first + second;
    		first = second;
    		second = newOne;
    	}
    	
        return first;
    }

    //方法二
    public int fib2(int n) {
    	return fib2(n, 0, 1, 0);
    }
    
    private int fib2(int n, int first, int second, int count) {
    	if(n == count) {
    		return first;
    	}
    	return fib2(n, second, first + second, count + 1);
    }
    
}
